<template>
  <div class="sharePhotosItem">
    <y-upload-img
      :url="myUrl"
      value-type="ObjectArray"
      @update="updateModel"
      re-upload
      business-sys-module-code="SHARE_PHOTO"
      :cropper-options="{
        fixed: businessId !== 'HB'
      }"
      :limit="1">
    </y-upload-img>
    <el-input
      v-model="model.uri"
      type="textarea" :autosize="{minRows: 1}"
      placeholder="请输入链接"></el-input>
  </div>
</template>

<script>
//const separate = '$';
export default {
  name: "sharePhotosItem",
  computed:{
    myUrl(){
      return this.model.icon ? [{
        url: this.model.icon,
        id: this.model.attachmentId
      }] : []
    }
  },
  props:{
    model: Object,
    businessId: {
      type: String,
      required: true
    }
  },
  data(){
    return{
      showPopover: false
    }
  },
  methods:{
    updateModel({type, file, preFile}){
      switch(type){
        case 'add':{
          this.model.attachmentId = file.id;
          this.model.icon = file.name;
          this.$emit('add');
          break;
        }
        case 'edit':{
          this.model.attachmentId = file.id;
          this.model.icon = file.name;
          break;
        }
        case 'delete':{
          this.$emit('delete', this.model);
          break;
        }
      }
    }
  }
}
</script>

<style scoped lang="less">
.sharePhotosItem{
  display: inline-block;
  vertical-align: top;
  margin-right: 10px;
  /deep/ .el-textarea{
    display: block;
    width: 148px;
    >.el-textarea__inner{
      border: none;
      border-bottom: @common-border;
      border-radius: 0;
      resize: none;
      padding: 5px;
      text-align: center;
    }
  }
}
</style>
